var quotation = new Vue({

    el: "#quotation",

    data: {
        //横向菜单列表
        goodsType: [],
        //询价单信息
        quoteOrCompare: {
            name: '',
            //报价单位
            quoteUnit:'',
            //报价金额
            quoteSum:'',
            //备注信息
            postscript:'',
            //报价时间
            quoteTime:'',
            //关联询价单ID
            quoteOrCompareId:'',
            //关联商家ID
            merchantId:'',
            //限额价格
            priceCap:'',
            //报价联系人
            quoteName:'',
            //报价联系人电话
            quoteTel:'',
            //品牌
            brand:'',
            //规格型号
            ggxh:'',
            //技术参数
            jscs:'',
            //数量
            num:'',
            //市场价格
            commodityMakPrc:'',
            //优惠率
            bateOfConcession:'',
            //单价
            dj:'',
            //总价
            total:'',
            //报价地点
            quoteAdrss:'',
            //交货时间
            consingmentTime:'',
            //交货地点
            consingmentAdress:'',
            // 售后承诺
            letterOfCommitment:'',
            //查询使用的开关
            ifQuery:''
        },

    },

    //提交时间方法
    methods: {
        //添加询价单信息
        submitQuote: function () {
            var _this = this;
            _this.SumPrice();
            $.post("/home/quotation/addQuotation",
                {"quotation": JSON.stringify(_this.quoteOrCompare)},
                function (data) {
                    debugger
                    if(data.code == 200){
                        _this.$notify({
                            message: '添加报价单成功！',
                            type: 'success'
                        });
                        $("#wrap-left").load("http://"+window.location.host+"/home/personOffers.html",function(){

                        });
                    }else{
                        _this.$notify({
                            message: '添加报价单失败！',
                            type: 'error'
                        });
                    }

                });
        },
        //计算总价
        SumPrice:function () {
            debugger
            var _this =  this;
            if(_this.quoteOrCompare.num==''){
                _this.quoteOrCompare.total='';
            }else{
                if(_this.quoteOrCompare.dj==''){
                    _this.quoteOrCompare.total=''
                    _this.$message({
                        message: '警告哦，您未输入单价，无法计算总金额！',
                        type: 'warning'
                    });
                }else{
                    _this.quoteOrCompare.total = Number(_this.quoteOrCompare.dj)*Number(_this.quoteOrCompare.num);
                }
            }

        },
        onSum:function () {
            var _this =  this;
            if(_this.quoteOrCompare.commodityMakPrc==""){
                _this.quoteOrCompare.bateOfConcession="";
            }else{
                if(_this.quoteOrCompare.quoteSum==''){
                    _this.quoteOrCompare.bateOfConcession='';
                    _this.$message({
                        message: '警告哦，商品报价为空，无法计算优惠率！',
                        type: 'warning'
                    });
                }else{
                    _this.quoteOrCompare.bateOfConcession=(((Number(_this.quoteOrCompare.commodityMakPrc)-Number(_this.quoteOrCompare.quoteSum))/Number(_this.quoteOrCompare.commodityMakPrc))*100).toFixed(2);
                }
            }

        },
        checkRole:function (str) {
            var _this = this;
            var RegPrice = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/;
            if(!RegPrice.test(str)){
                _this.$notify({
                    message: "请正确填写,必须为数字.",
                    type: 'error'
                });
            }
        },
        Value:function (quoteOrCompare,ifQuery) {
            var _this=this;
            _this.quoteOrCompare=quoteOrCompare;
            _this.quoteOrCompare.ifQuery=ifQuery;
        },
    },

    //页面加载后的初始化方法
    created: function () {
        var _this = this;
        var goodsTypeList = [
            {href: "designatedService.html", name: "定点服务", url: "#"},
            {href: "../home/offers.html", name: "询价表", url: "#"},
            {href: "../home/inquiryDetails.html", name: "报价单位", url: "#"},
            {href: "../home/quotation.html", name: "报价单", url: "#"},
            {href: "../home/bidding.html", name: "发起询价", url: "#"}
        ];
        _this.goodsType = goodsTypeList;//后台动态添加进入
        //查询跟自己 有关系的地址
        $.post("/home/addressManager/selectByUserAndTypeCheck", "", function (data) {
            debugger
            if(data.data.addressManagers.address!=null&&data.data.addressManagers.address!=''){
            _this.quoteOrCompare.quoteAdrss = data.data.addressManagers.address;
            }
        });
    }
});
trackValue=function (quoteOrCompare,ifQuery) {
    var _this=this;
    Value(quoteOrCompare,ifQuery);
    // _this.quoteOrCompare=quoteOrCompare;
    // _this.quoteOrCompare.ifQuery=ifQuery;
}